package com.zkingsoft.actions.admin;

import java.util.Arrays;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.actions.common.BaseController;
import com.zkingsoft.constance.Dictionary;
import com.zkingsoft.model.ArticleType;
import com.zkingsoft.plugin.pojo.PaginationVO;
import com.zkingsoft.plugin.util.WebUtil;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.services.ArticleTypeService;

/**
 * @author dingchuan
 * @date 2016-07-15 11:19
 * 文章类型Controller
 */
@Controller
@RequestMapping(value = "admin/articleType")
public class ArticleTypeController extends BaseController{

	@Resource
	private ArticleTypeService currentService;
	
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(ArticleType articleType, PaginationVO pageVo) {
		return showList(currentService, articleType, pageVo);
	}
		
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/all")
	public @ResponseBody AjaxResult all(ArticleType articleType) {
		return new AjaxResult(AjaxResult.STATUS_OK, null, "执行成功",	currentService.findByModel(articleType), 0);
	}
	/**
	 * 内部培训列表显示
	 */
	@RequestMapping(value = "/queryAll")
	public @ResponseBody AjaxResult queryAll(ArticleType articleType) {
		return new AjaxResult(AjaxResult.STATUS_OK, null, "执行成功",	currentService.findByModel(articleType), 0);
	}
	
/*	*//**
	 * 美度学院列表显示(培训资料)
	 *//*
	@RequestMapping(value = "/pxzl")
	public @ResponseBody AjaxResult pxzl(ArticleType articleType) {
		articleType.setType(Dictionary.ARTICEL_TYPE_NAME_MDXY);
		return new AjaxResult(AjaxResult.STATUS_OK, null, "执行成功",	currentService.findByModel(articleType), 0);
	}*/
	
	/**
	 * 新增或者修改页面
	 */   	
   	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(ArticleType articleType) {
		if (articleType.getId() != null) {
			return modify(currentService, articleType, "文章类型");
		} else {
			return add(currentService, articleType, "文章类型");
		}
	}
   	
   	
	
   	/**
	 * 进入修改界面
	 */   
   	@RequestMapping(value = "/editForm")
	public String editForm(Long id) {
		ArticleType articleType;
		if (id != null) {
			articleType = currentService.findById(id);
			WebUtil.getRequest().setAttribute("obj", articleType);
		}
		return "admin/articleTypeManage-form";
	}	
 	/**
	 * 进入美度学院修改页面
	 */   
   	@RequestMapping(value = "/updateForm")
	public String updateForm(Long id) {
		ArticleType articleType;
		if (id != null) {
			articleType = currentService.findById(id);
			WebUtil.getRequest().setAttribute("obj", articleType);
		}
		return "admin/operate/trainingMaterialsType-form";
	}	
   	
   	
   	/**
	 * 删除
	 */  
 	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		return remove(currentService, keys);
	}
 	
 	@RequestMapping(value = "/findById")
	public @ResponseBody AjaxResult findById(Long id) {
		ArticleType articleType = super.findById(currentService, id);
		return new AjaxResult(AjaxResult.STATUS_OK, null, null, Arrays.asList(articleType), 0);
	}
 	
}